package com.bdqn.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.crm.pojo.CstLost;
import com.bdqn.crm.service.CstLostService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
public class CstLostController {

    @Resource
    private CstLostService cstLostService;


    @RequestMapping(value = "lost/list")
    public String list(Model model,String lstCustName,String lstCustManagerName,Long pageIndex){

        //数据回显
        model.addAttribute("lstCustName",lstCustName);
        model.addAttribute("lstCustManagerName",lstCustManagerName);

        //如果为空，查询第一页
        if (pageIndex == null){
            pageIndex = 1L;
        }

        Page<CstLost> page = new Page<>();
        page.setCurrent(pageIndex);
        IPage<CstLost> cstLostIPage = cstLostService.page(lstCustName,lstCustManagerName,page);
        model.addAttribute("rolePage",cstLostIPage);
        return "lost/list";
    }

    @GetMapping(value = "lostc/edit")
    public String edit(Model model,Long lstId){
        CstLost cstLost = cstLostService.selectId(lstId);
        model.addAttribute("losts",cstLost);
        return "lost/edit";
    }
    @PostMapping(value = "lost/save")
    public String save(CstLost cstLost){
        cstLostService.saveOrUpdate(cstLost);
        return "redirect:/lost/list";
    }
}
